class A implements Runnable {
	int i;

	public void run() {
		try {
			Thread.sleep(5000);
			i = 10;
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("End of Thread A");
	}
}

public class TestThreadJoin {

	public static void main(String args[]) {
		try {
			A a = new A();
			Thread t = new Thread(a);
			t.start();
			t.join(); // Without this t.join(), j will print 0 as main method
						// gets finished before A
			int j = a.i;
			System.out.println("j = " + j);
		} catch (Exception e) {
		}
		System.out.println("End of main..");
	}
}
